<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<ui:composition template="template.xhtml">
	<ui:define name="content">
		<h:form id="form01">
			<p:panel header="Building List" style="text-align:center">
				<div style="float: left">
					<p:commandButton id="addNewBtn" ajax="true"
						value="Add New Building"
						actionListener="#{buildingListControler.startAddBuilding}"
						icon="ui-icon-plus" update=":form04:detailDialog"
						rendered="#{mainMenuControler.hasUserRole('admin')}" />
				</div>
				<br />
				<br />
				<br />
				<p:dataTable id="buildingTable" widgetVar="widgetVar_w"
					filteredValue="#{buildingListControler.filteredTerms}"
					rendered="#{mainMenuControler.hasUserRole('admin') || mainMenuControler.hasUserRole('building')}"
					value="#{buildingListControler.buildingList}" var="building"
					rows="15" paginator="true" paginatorAlwaysVisible="true"
					paginatorPosition="bottom" first="#{buildingListControler.first}"
					paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink}">
					<p:column style="width:20%"
						headerText="#{dictionaryControler.dictionary['Name']}">
						<h:outputText value="#{building.name}" />
					</p:column>

					<p:column style="width:4%"
						headerText="#{dictionaryControler.dictionary['Floors']}">
						<h:outputText value="#{building.floorCount}">
						</h:outputText>
					</p:column>
					<p:column style="width:3%"
						rendered="#{mainMenuControler.hasUserRole('admin')}"
						headerText="#{dictionaryControler.dictionary['Edit']}">
						<p:commandButton id="editButton" update=":form04:detailDialog_1"
							action="#{buildingListControler.startEditBuilding}"
							icon="ui-icon-pencil">
							<f:setPropertyActionListener value="#{building}"
								target="#{buildingListControler.selectedBuilding}" />
						</p:commandButton>
					</p:column>
					<p:column style="width:3%"
						rendered="#{mainMenuControler.hasUserRole('admin')}"
						headerText="#{dictionaryControler.dictionary['Delete']}">
						<p:commandButton id="deleteButton" ajax="true"
							action="#{buildingListControler.deleteBuilding}"
							update=":form01:buildingTable" icon="ui-icon-close" oncomplete="PF('widgetVar_w').clearFilters();"
							style="margin-right:5px">
							<f:setPropertyActionListener value="#{building}"
								target="#{buildingListControler.selectedBuilding}" />
							<p:confirm
								header="#{dictionaryControler.dictionary['Confirmation']}"
								message="#{dictionaryControler.dictionary['Are you sure']}?"
								icon="ui-icon-alert" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:panel>
			<h:outputText value="Access Denied, please contact the administrator"
				rendered="#{!(mainMenuControler.hasUserRole('admin') || mainMenuControler.hasUserRole('building'))}"
				style="width:100%; height:50%; text-align:center; font-size:150% !important;position:absolute; margin-left:0; margin-right:0; margin-top:0;margin-bottom:0" />
		</h:form>
	</ui:define>

	<ui:define name="dialog">
		<h:form id="form04">
			<p:dialog id="detailDialog" widgetVar="detailDialog_w" modal="true"
				showEffect="fade" resizable="false" draggable="true"
				closable="false" visible="#{buildingListControler.addMode}"
				header="#{dictionaryControler.dictionary['Building']} #{dictionaryControler.dictionary['Add']}">
				<p:focus context="detailDialog" for="addBtn" />
				<p:panelGrid columns="2">
					<h:outputText value="#{dictionaryControler.dictionary['Name']}" />
					<p:inputText value="#{buildingListControler.newBuilding.name}"
						maxlength="30" required="true"
						rendered="#{buildingListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Name']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Floors']}" />
					<p:inputText value="#{buildingListControler.newBuilding.floorCount}"
						maxlength="30" required="true"
						rendered="#{buildingListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Floors']} #{dictionaryControler.dictionary['Required']}" />
				</p:panelGrid>
				<br />
				<div style="text-align: right">
					<p:commandButton id="addBtn"
						value="#{dictionaryControler.dictionary['Add']}" ajax="true"
						style="margin-right:5px" oncomplete="PF('widgetVar_w').clearFilters();"
						actionListener="#{buildingListControler.addNewBuilding}"
						update="detailDialog,:form01:buildingTable" />
					<p:commandButton id="cancelBtn"
						value="#{dictionaryControler.dictionary['Cancel']}" ajax="true"
						actionListener="#{buildingListControler.cancelAddBuilding}"
						immediate="true" update="detailDialog" />
				</div>
				<p:messages showDetail="false" />
			</p:dialog>
			<p:dialog id="detailDialog_1" widgetVar="detailDialog_e"
				resizable="false" draggable="true" closable="false"
				visible="#{buildingListControler.editMode}" modal="true"
				header="#{dictionaryControler.dictionary['Building']} #{dictionaryControler.dictionary['Edit']}">
				<p:panelGrid columns="2">
					<h:outputText value="#{dictionaryControler.dictionary['Name']}" />
					<p:inputText
						value="#{buildingListControler.selectedBuilding.name}"
						maxlength="30" required="true"
						rendered="#{buildingListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Title']} #{dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Floors']}" />
					<p:inputText value="#{buildingListControler.selectedBuilding.floorCount}"
						maxlength="30" required="true"
						rendered="#{buildingListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Floors']} #{dictionaryControler.dictionary['Required']}" />
				</p:panelGrid>
				<br />
				<div style="text-align: right">
					<p:commandButton id="saveBtn_1"
						value="#{dictionaryControler.dictionary['Save']}" ajax="true"
						style="margin-right:5px"
						action="#{buildingListControler.saveEditBuilding}"
						update=":form01:buildingTable,detailDialog_1" />
					<p:commandButton id="cancelBtn_1"
						value="#{dictionaryControler.dictionary['Cancel']}" ajax="true"
						action="#{buildingListControler.cancelEditBuilding}"
						immediate="true" update="detailDialog_1" />
				</div>
				<p:messages />
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>
</html>
